package com.project.senven.model.controller;

import com.project.senven.commons.bean.User;
import com.project.senven.commons.uitl.JsonResult;
import com.project.senven.model.service.UserService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
@Slf4j
@RestController
@RequestMapping("/ai_rolephay")
@CrossOrigin
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("add_es")
    public void add_es(){
        userService.batchAddPdfsToVectorStore();
    }

    //用户注册
    @PostMapping("/add_user")
    public JsonResult add(@RequestBody User user){
        return userService.register(user);
    }

    //添加向量知识库
    @GetMapping("/add_db")
    public void add_db(){
        userService.add();
    }

    //查询向量数据库
    @GetMapping("/find_db")
    public void find_db(){
        userService.find();
    }

    //最好不加produces，因为他默认就是流式，加了有可能出错
    //@RequestMapping(value = "/stream", produces = "text/event-stream;charset=utf-8")
    @RequestMapping("/stream")
    public Flux<String> stream(@RequestParam("question") String question) {
        log.info("question = {}", question);
        return userService.stream(question);
    }

    //用户登录
    @PostMapping("/user_login")
    public JsonResult login(User user){
        return userService.login(user);
    }

}
